package com.android.customviewgroup;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.customviewgroup.viewholder.ViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 小神有礼了
 * Time: 2/20/22 1:53 AM
 * Mail: 5267621@qq.com
 */
public abstract class ViewGroupAdapter<T> implements IViewGroupAdapter {

    private List<T> mDataSet;
    private Context mContext;

    public abstract void convert(ViewHolder viewHolder, T item, int position);

    public abstract int getItemLayout();

    public ViewGroupAdapter(Context context, List<T> mDataSet) {
        this.mContext = context;
        this.mDataSet = mDataSet == null ? new ArrayList<T>() : mDataSet;
    }

    @Override
    public View getView(ViewGroup parent, int pos) {
        View itemView = LayoutInflater.from(mContext).inflate(getItemLayout(), parent, false);
        ViewHolder holder = (ViewHolder) ViewHolder.create(itemView);
        convert(holder, mDataSet.get(pos), pos);
        return holder.getConvertView();
    }

    @Override
    public int getCount() {
        return mDataSet.size();
    }

    public List<T> getData() {
        return mDataSet;
    }
}
